<?php

namespace App\Models;

class UsersPaymentModel
{
    /**
     * 查询用户绑定收款码
     * entry conn,uid
     * return int
     * */
    public static function QueryUserPaymentInsideAll($conn,$uid){
        $querySql="select `payment`,`status` from `users_payment` where `user_id` = $uid";
        return $conn->readConn($querySql,true);
    }
    /**
     * 查询用户绑定收款码
     * entry conn,uid
     * return int
     * */
    public static function QueryUserPaymentInside($conn,$uid){
        $querySql="select `payment` from `users_payment` where `user_id` = $uid and `status` in(2,3) group by `payment`";
        return $conn->readConn($querySql,true);
    }
    /**
     * 查询用户收款码(订单)
     * entry conn,uid
     * return int
     * */
    public static function QueryUserOrderPaymentInside($conn,$uid,$payment){
        $querySql="select `content`,`payment`,`mobile`,`real_name`,`new_content` from `users_payment` where `user_id` = $uid and `payment` in($payment) and `status` in(2,3)";
        return $conn->readConn($querySql,true);
    }
    /**
     * 获取用户付款信息
     * entry conn,uid
     * return int
     * */
    public static function getUsersPaymentOne($conn,$uid){
        $querySql="select `mobile` from `users_payment` where `user_id` = $uid and `status` in(2,3) limit 1";
        return $conn->readConn($querySql)["mobile"];
    }
    /**
     * 获取用户付款信息
     * entry conn,uid
     * return int
     * */
    public static function getUsersPaymentName($conn,$uid){
        $querySql="select `real_name` from `users_payment` where `user_id` = $uid and `status` in(2,3) limit 1";
        return $conn->readConn($querySql)["real_name"];
    }
    /**
     * 获取用户付款信息
     * entry conn,UsersPaymentExample
     * return int
     * */
    public static function getUsersPaymentInside($conn,$UsersPaymentExample){
        $querySql="select `id`,`mobile`,`real_name`,`content`,`new_content`,`payment`,`status` from `users_payment` where `user_id` = $UsersPaymentExample->user_id and `payment` = '$UsersPaymentExample->payment' limit 1";
        return $conn->readConn($querySql);
    }
    /**
     * 插入用户付款信息
     * entry conn,$UsersPaymentExample
     * return int
     * */
    public static function insertUserPaymentInside($conn,$UsersPaymentExample){
        $insertSql = "insert into `users_payment`(`user_id`,`mobile`,`real_name`,`payment`,`status`,`content`,`new_content`,`create_time`,`update_time`) values ($UsersPaymentExample->user_id,'$UsersPaymentExample->mobile','$UsersPaymentExample->real_name',$UsersPaymentExample->payment,$UsersPaymentExample->status,'$UsersPaymentExample->content','$UsersPaymentExample->new_content','$UsersPaymentExample->create_time','$UsersPaymentExample->update_time')";
        return $conn->executeConn($insertSql);
    }

    /**
     * 修改付款信息加字段
     * entry UsersCollExample
     * return int
     * */
    public static function editInside($conn,$Example){
        $joinSql="";
        if($Example->mobile !=null){
            $joinSql.=" `mobile` = '$Example->mobile',";
        }
        if($Example->real_name !=null){
            $joinSql.=" `real_name` = '$Example->real_name',";
        }
        if($Example->id_card !=null){
            $joinSql.=" `id_card` = '$Example->id_card',";
        }
        if($Example->status !=null){
            $joinSql.=" `status` = '$Example->status',";
        }
        if($Example->content !=null){
            $joinSql.=" `content` = '$Example->content',";
        }
        if($Example->new_content !=null){
            $joinSql.=" `new_content` = '$Example->new_content',";
        }
        if($Example->update_time !=null){
            $joinSql.=" `update_time` = '$Example->update_time',";
        }
        if($joinSql !=null){
            $innerJoin = rtrim($joinSql,",");
            $upUserSql="UPDATE  `users_payment` SET $innerJoin WHERE `id` = '$Example->id'";
            return $conn->executeConn($upUserSql);
        }
    }
}